/*----------------------------------------------------------------------
  - File name      : tmt.c
  - Author         : Quark Team
  - Update date    : 2020-09-28                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Task Management Tool module.
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "main.h"
#include "tmt.h"
#include "app.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: Task definition                          |
--------------------------------------------------------*/

static TASK_COMPONENTS Task_Comps[]=
{
	{0, 20, 20,button_handler}, /* task 1  500ms */
//	{0,20,20,pid_task_handler},
	/* Add new task here */
};

/*--------------------------------------------------------
| @Description: Maximum number of task lists             |
--------------------------------------------------------*/

uint8 Tasks_Max = sizeof(Task_Comps)/sizeof(Task_Comps[0]);

/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: Task remarks handler function            |
| @param      : None                                     |
| @return     : None                                     |
--------------------------------------------------------*/

void Task_Marks_Handler_Callback(void)
{
	uint8 i;
	for(i=0; i<Tasks_Max; i++)    
	{
		 /* If time arrives */
		Task_Comps[i].TIMCount--;
		if((Task_Comps[i].TIMCount) == 0) 
		{
			Task_Comps[i].TIMCount = Task_Comps[i].TRITime;
			Task_Comps[i].Run = 1; /* The task can be run */  
		}
	}
}

/*--------------------------------------------------------
| @Description: Task process handler function            |
| @param      : None                                     |
| @return     : None                                     |
--------------------------------------------------------*/

void Task_Pro_Handler_Callback(void)
{
	uint8 i;
	for(i=0; i<Tasks_Max; i++)      
	{
		if(Task_Comps[i].Run) /* If task can be run */
		{
			Task_Comps[i].Run = 0;    /* Flag clear 0 */
			Task_Comps[i].TaskHook();  /* Run task */
		}
	} 
}

/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/
